﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App.Utility;
using System.Globalization;

namespace App.Account.Models.Forms
{
    [Serializable]
    public class ChangePassword : IRuleEntity
    {
        public string UserName { get; set; }
        public string CurrentPassword { get; set; }
        public string NewPassword { get; set; }
        public string ConfirmPassword { get; set; }




        public List<RuleViolation> GetRuleViolations()
        {
            List<RuleViolation> validationIssues = new List<RuleViolation>();


            // Basic parameter validation
            if (String.IsNullOrEmpty(CurrentPassword))
            {
                validationIssues.Add(new RuleViolation()
                {
                    PropertyName = "CurrentPassword",
                    ErrorMessage = "You must specify a current password."
                });
            }
            if (NewPassword == null || NewPassword.Length < Properties.Settings.Default.MinRequiredPasswordLength)
            {
                validationIssues.Add(new RuleViolation()
                {
                    PropertyName = "NewPassword",
                    ErrorMessage = String.Format(CultureInfo.CurrentCulture,
                         "You must specify a new password of {0} or more characters.",
                         Properties.Settings.Default.MinRequiredPasswordLength)
                });
            }
            if (!String.Equals(NewPassword, ConfirmPassword, StringComparison.Ordinal))
            {
                validationIssues.Add(new RuleViolation()
                {
                    PropertyName = "_FORM",
                    ErrorMessage = "The new password and confirmation password do not match."
                });
            }

            return validationIssues;
        }
    }
}
